import cv2
import numpy as np

# Load the image
image = cv2.imread("00042-387765739.jpeg")

# Calculate the pixel density of each pixel in the image using a Gaussian filter
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
density = cv2.GaussianBlur(gray, (0, 0), sigmaX=3, sigmaY=3, borderType=cv2.BORDER_REPLICATE)

# Resize the density map to the size of the image using bicubic interpolation
resized_density = cv2.resize(density, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_CUBIC)

# Create a resolution map using the density values and apply a heatmap color map
heatmap = cv2.applyColorMap((resized_density / np.max(resized_density) * 255).astype(np.uint8), cv2.COLORMAP_JET)

# Display the heatmap
cv2.imshow("Resolution map", heatmap)
cv2.waitKey(0)
cv2.destroyAllWindows()

# import cv2
# import numpy as np

# # Load the image
# image = cv2.imread("00042-387765739.jpeg")

# # Calculate the pixel density of each pixel in the image using a Gaussian filter
# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# density = cv2.GaussianBlur(gray, (0, 0), sigmaX=3, sigmaY=3, borderType=cv2.BORDER_REPLICATE)

# # Resize the density map to the size of the image using bicubic interpolation
# resized_density = cv2.resize(density, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_CUBIC)

# # Create a resolution map using the density values
# resolution_map = (resized_density / np.max(resized_density) * 255).astype(np.uint8)

# # Display the resolution map
# cv2.imshow("Resolution map", resolution_map)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

# import cv2
# import numpy as np

# # Load the image
# image = cv2.imread("00042-387765739.jpeg")
# print(image.shape)

# # Set the size of the tiles
# tile_size = (100, 100)

# # Calculate the pixel density of each tile
# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# height, width = gray.shape
# density = np.zeros((height // tile_size[1], width // tile_size[0]), dtype=np.float32)
# print(density.shape)

# for i in range(0, height, tile_size[1]):
#     for j in range(0, width, tile_size[0]):
#         tile = gray[i:i+tile_size[1], j:j+tile_size[0]]
#         density[i // tile_size[1], j // tile_size[0]] = np.sum(tile) / (tile_size[0] * tile_size[1])

# # Resize the density map to the size of the image using bicubic interpolation
# resized_density = cv2.resize(density, (width, height), interpolation=cv2.INTER_CUBIC)

# # Create a resolution map using the density values
# resolution_map = (resized_density / np.max(resized_density) * 255).astype(np.uint8)

# # Display the resolution map
# cv2.imshow("Resolution map", resolution_map)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
